return ret;
}
+gboolean
+ostree_repo_mode_from_string (const char *mode,
+ OstreeRepoMode *out_mode,
+ GError **error)
+{
+ gboolean ret = FALSE;
+ OstreeRepoMode ret_mode;
+
+ if (strcmp (mode, "bare") == 0)
+ ret_mode = OSTREE_REPO_MODE_BARE;
+ else if (strcmp (mode, "archive") == 0)
+ ret_mode = OSTREE_REPO_MODE_ARCHIVE;
+ else
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Invalid mode '%s' in repository configuration", mode);
+ goto out;
+ }
+
+ ret = TRUE;
+ *out_mode = ret_mode;
+ out:
+ return ret;
+}
+
gboolean
ostree_repo_check (OstreeRepo *self, GError **error)
{
"bare", &mode, error))
goto out;
- if (strcmp (mode, "bare") == 0)
- self->mode = OSTREE_REPO_MODE_BARE;
- else if (strcmp (mode, "archive") == 0)
- self->mode = OSTREE_REPO_MODE_ARCHIVE;
- else
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Invalid mode '%s' in repository configuration", mode);
- goto out;
- }
+ if (!ostree_repo_mode_from_string (mode, &self->mode, error))
+ goto out;
}
if (!ot_keyfile_get_value_with_default (self->config, "core", "parent",
return ret;
}
+static gboolean
+load_remote_repo_config (OtPullData *pull_data,
+ GKeyFile **out_keyfile,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gboolean ret = FALSE;
+ ot_lfree char *contents = NULL;
+ GKeyFile *ret_keyfile = NULL;
+ SoupURI *target_uri = NULL;
+
+ target_uri = suburi_new (pull_data->base_uri, "config", NULL);
+
+ if (!fetch_uri_contents_utf8 (pull_data, target_uri, &contents,
+ cancellable, error))
+ goto out;
+
+ ret_keyfile = g_key_file_new ();
+ if (!g_key_file_load_from_data (ret_keyfile, contents, strlen (contents),
+ 0, error))
+ goto out;
+
+ ret = TRUE;
+ ot_transfer_out_value (out_keyfile, &ret_keyfile);
+ out:
+ g_clear_pointer (&ret_keyfile, (GDestroyNotify) g_key_file_unref);
+ return ret;
+}
+
static gboolean
ostree_builtin_pull (int argc, char **argv, GFile *repo_path, GError **error)
{
gpointer key, value;
int i;
GCancellable *cancellable = NULL;
+ OstreeRepoMode remote_repo_mode;
ot_lfree char *remote_key = NULL;
ot_lobj OstreeRepo *repo = NULL;
ot_lfree char *path = NULL;
ot_lhash GHashTable *updated_refs = NULL;
ot_lhash GHashTable *commits_to_fetch = NULL;
ot_lfree char *branch_rev = NULL;
+ ot_lfree char *remote_mode_str = NULL;
OtPullData pull_data_real;
OtPullData *pull_data = &pull_data_real;
SoupURI *summary_uri = NULL;
GKeyFile *config = NULL;
+ GKeyFile *remote_config = NULL;
char **configured_branches = NULL;
guint64 bytes_transferred;
goto out;
}
+ if (!load_remote_repo_config (pull_data, &remote_config, cancellable, error))
+ goto out;
+
+ if (!ot_keyfile_get_value_with_default (remote_config, "core", "mode", "bare",
+ &remote_mode_str, error))
+ goto out;
+
+ if (!ostree_repo_mode_from_string (remote_mode_str, &remote_repo_mode, error))
+ goto out;
+
+ switch (remote_repo_mode)
+ {
+ case OSTREE_REPO_MODE_ARCHIVE:
+ break;
+ default:
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Can't pull from archives with mode \"%s\"",
+ remote_mode_str);
+ }
+
requested_refs_to_fetch = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
updated_refs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
commits_to_fetch = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
g_clear_pointer (&pull_data->file_checksums_to_fetch, (GDestroyNotify) g_hash_table_unref);
g_clear_pointer (&pull_data->cached_meta_pack_indexes, (GDestroyNotify) g_ptr_array_unref);
g_clear_pointer (&pull_data->cached_data_pack_indexes, (GDestroyNotify) g_ptr_array_unref);
+ g_clear_pointer (&remote_config, (GDestroyNotify) g_key_file_unref);
if (summary_uri)
soup_uri_free (summary_uri);
return ret;